package com.xhorse.lockplatform.comm.model;


/**
 * 带有ID的表单基类
 *
 * @author Stay
 * @date 2017-11-30
 */
public abstract class BaseIdForm<T extends BaseId> {
    protected Integer id;

    /**
     * 创建对象
     *
     * @return
     */
    public abstract T newObj();

    /**
     * 设置值
     *
     * @param obj
     */
    public abstract void populateObj(T obj);

    public T toObj() {
        T t = newObj();
        t.setId(id);
        populateObj(t);
        return t;
    }

    public boolean isModified() {
        return id != null && id > 0;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
}
